var Zhongchou = require("../../../class/admin/zhongchou.c");
var _Zhongchou = new Zhongchou();
module.exports = {
    prefix: "/admin/zhongchou/",
    post: {
        "create": {
            des: {
                name: "createZhongchou",
                content: "创建众筹",
                params: [
                	{
                		key:'name',
                		type:'string'
                	},
                    {
                    	key: "car_id",
                        type: "string"
                    },
                    {
                    	key:'number',
                    	type:'Int'
                    },
                    {
                    	key:'totalprice',
                    	type:'Number'
                    },
                    {
                    	key:'zcprice',
                    	type:'Number'
                    }
                ]
            },
            method: function* () {
                var self = this;
                var data = yield new Zhongchou(self.request.body,self.session.admin).save();
                self.body = data;

                /*
                print("创建众筹");
                try {
                    var _module_list = yield new Module().getAll();
                    self.body = _module_list;
                } catch (e) {
                    self.body = printError(e);
                };*/
            }
        },
        "update":{
        	des: {
                name: "updateZhongchou",
                content: "修改众筹",
                params: [
                	{
                		key:'_id',
                		type:'string'
                	},
                	{
                		key:'name',
                		type:'string'
                	},
                    {
                    	key: "car_id",
                        type: "string"
                    },
                    {
                    	key:'number',
                    	type:'Int'
                    },
                    {
                    	key:'totalprice',
                    	type:'Number'
                    },
                    {
                    	key:'zcprice',
                    	type:'Number'
                    }
                ]
            },
            method: function* () {
                var self = this;
                var data = yield new Zhongchou(self.request.body,self.session.admin).update();
                self.body = data;

                /*
                print("创建众筹");
                try {
                    var _module_list = yield new Module().getAll();
                    self.body = _module_list;
                } catch (e) {
                    self.body = printError(e);
                };*/
            }
        }
    },
    delete:{
    	'delete/:_id':{
    		 des: {
                name: "postDelete",
                content: "删除指定众筹",
                params: [
                    {
                        params: "_id",
                        type: "string"
                    }
                ]
            },
            method: function* () {
                var self = this;
                try {
                    var _id = self.params._id;
                    var _post = yield _Post.delete(_id);
                    self.body = _post;
                    if (_post.type !== "error") {
                        yield _Module.upgradepost(_post._module);
                    };
                } catch (e) {
                    self.body = printError(e);
                };
            }
    	}
    }
}
